/**
* This program is distributed "as-is" and is not
* documented beyond the scope of the source-code
* comments.											
*
* @author:	JR Lanteigne
* @class:	JET 1 Spring 2014
* @title:	April_30.cpp
*/

#include "macros.h"
#include "equations.h"

int main() {

	// init all variables
	static double radius = 0;
	static double circumference = 0;
	static double area = 0; // circle area
	static double height = 0;
	static double _area = 0; // cylinder side surface area
	static double total = 0; // radius total

	static int i = 0; // counter
		
	while(radius != -1 && height != -1) {
		// get a fresh input buffer
		fflush(stdin);

		// initial run, start on a fresh screen
		if(i == 0)
			cls();

		srand((int)time(0)); // seed rng

		double x = ((double)(rand() % 10000)/(double)(rand() % 50 + 1)),
			   y = ((double)(rand() % 10000)/(double)(rand() % 50 + 1));

		if(!promptRadius(&radius) || !promptHeight(&height)) {
			cls();
			printf("\nInvalid input.");
			_wait(2);
			continue;
		}

		if(radius == -1 || height == -1)
			break; // exit program

		cls();

		/* Math to calculate cylinder parameters */

		setCircum(&circumference, radius);
		setTotalArea(&_area, height, radius);
		setCircleArea(&area, radius);


		// get max precision, 15 places, drop trailing zeroes
		printf("\nHeight:\t\t %.15g ", height); // print user defined height
		printf("\nRadius:\t\t %.15g ", radius); // print user defined radius
		printf("\nCircumference:\t %.15g ", circumference); // print calculated circumference
		printf("\nCircle area:\t %.15g ", area); // print area of a single circle (top or bottom)
		printf("\nCylinder area:\t %.15g ", _area); // area of two circles + shaft area
		total += radius; // increment total count
		i++; // increment calculations

		// "Total of n calculation(s) and total radius length x"
		printf("\n\nTotal of %d calculation%s and total radius length %.15g\n", i, (i == 1) ? "" : "s", total);

	}

	return 0; // finish execution

}